
/**
 * AppleIIGo
 * Apple II Memory Expansion Card class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "AppleIIMemoryExpansionCard.h"

AppleIIMemoryExpansionCard::AppleIIMemoryExpansionCard(Motherboard *
													   motherboard,
													   char * slotDeviceName) :
InternalMemoryExpansion(motherboard, slotDeviceName) {
}

void AppleIIMemoryExpansionCard::onMemoryRequested() {
	InternalMemoryExpansion::onMemoryRequested();
	romMemoryOffset = motherboard->getMemory()->
		requestMemory(APPLEIIMEMORYEXPANSIONCARD_ROM_BYTENUM);
}

void AppleIIMemoryExpansionCard::onMemoryAllocated() {
	InternalMemoryExpansion::onMemoryAllocated();
	romMemory = motherboard->getMemory()->getMemory(romMemoryOffset);
	char * romImage = "Apple II Memory Expansion ROM.bin";
	motherboard->getResources()->
		readResource(romMemory,
					 APPLEIIMEMORYEXPANSIONCARD_ROM_BYTENUM,
					 romImage);
}

UINT8 AppleIIMemoryExpansionCard::readMemory(UINT16 address) {
	if ((address & 0xff8) == 0xff8)
		return timingGenerator->readFloatingBus();
	else
		return romMemory[address & 0xfff];
}
